package leetcode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/***
 * 题目：两数之和
 * 链接：https://leetcode.cn/problems/two-sum/description/
 */
public class TwoSum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int target = Integer.parseInt(sc.nextLine());
        // 输入整数数组
        int[] nums = Arrays.stream(sc.nextLine().split("\\s+"))
                .mapToInt(Integer::parseInt).toArray();
        int[] twoSum = twoSum(nums, target);
        System.out.println(Arrays.toString(twoSum));


    }
    public static int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(map.containsKey(target-nums[i])){
                return new int[]{map.get(target - nums[i]), i};
            }else
                map.put(nums[i],i);
        }
        return new int[0];
    }
}
